#include "gameobject.h"


sf::Packet& operator <<(sf::Packet& Packet, const GameObject& obj)
{
	Packet << obj.id << obj.parent << obj.type << obj.pos.x << obj.pos.y << obj.angle << obj.angVel;
	switch (obj.type)
	{
		case OBJECT_TYPE::PLANET:
			Packet << obj.size << obj.mass;
			break;

		case OBJECT_TYPE::SHIP:
			Packet << obj.size << obj.mass << obj.vel.x << obj.vel.y << obj.acc.x << obj.acc.y << obj.controls;
			break;

		case OBJECT_TYPE::WEAPON:
			Packet << obj.size << obj.mass << obj.vel.x << obj.vel.y << obj.acc.x << obj.acc.y << obj.weaponCooldown;
			break;

		default:
			break;
	}
	return Packet;
}

sf::Packet& operator >>(sf::Packet& Packet, GameObject& obj)
{
	Packet >> obj.id >> obj.parent >> obj.type >> obj.pos.x >> obj.pos.y >> obj.angle >> obj.angVel;
	switch (obj.type)
	{
		case OBJECT_TYPE::PLANET:
			Packet >> obj.size >> obj.mass;
			break;

		case OBJECT_TYPE::SHIP:
			Packet >> obj.size >> obj.mass >> obj.vel.x >> obj.vel.y >> obj.acc.x >> obj.acc.y >> obj.controls;
			break;

		case OBJECT_TYPE::WEAPON:
			Packet >> obj.size >> obj.mass >> obj.vel.x >> obj.vel.y >> obj.acc.x >> obj.acc.y >> obj.weaponCooldown;
			break;

		default:
			break;
	}
	return Packet;
}
